﻿using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

namespace AwesomeChromeFormUI.Utils
{
    public class ImageConverter
    {

        /// <summary>
        /// 像素转图片
        /// 
        /// ByteArrayToImage(imageData, "output.png", ImageFormat.Png);
        /// 
        /// ByteArrayToImage(imageData, "output.jpg", ImageFormat.Jpeg);
        /// </summary>
        /// <param name="data">像素数据数组</param>
        /// <param name="outputPath">保存路径</param>
        /// <param name="format">图片格式png/jpg</param>
        public static void ByteArrayToImage(byte[] data, string outputPath, ImageFormat format)
        {
            using (MemoryStream ms = new MemoryStream(data))
            {
                using (Bitmap bitmap = new Bitmap(ms))
                {
                    bitmap.Save(outputPath, format);
                }
            }
        }
    }
}
